package com.kyc.kycxkplaygame.greendao.manager;

import com.kyc.kycxkplaygame.PlayGameApplication;
import com.kyc.kycxkplaygame.greendao.UserInfoGdBean;
import com.kyc.kycxkplaygame.greendao.gen.UserInfoGdBeanDao;

import java.util.List;

/**
 * Created by Administrator on 2017/12/21.
 */

public class UserInfoManager {
    public static UserInfoManager mHelp;
    private UserInfoGdBeanDao mDao;

    public static UserInfoManager getInstance(){
        if(mHelp==null){
            mHelp = new UserInfoManager();
            return mHelp;
        }else {
            return mHelp;
        }
    }

    private UserInfoManager(){
        mDao =  PlayGameApplication.getInstance().getDaoSession().getUserInfoGdBeanDao();
    }

    public void deleteUserInfo(UserInfoGdBean entity){
        mDao.delete(entity);
    }

    public void insertUserInfo(UserInfoGdBean entity){
        mDao.insertOrReplace(entity);
    }

    public void updateUserInfo(UserInfoGdBean entity){
        UserInfoGdBean userInfoGdBean = new UserInfoGdBean();
        userInfoGdBean.setLevel(entity.getLevel());
        //userInfoGdBean.setStarcount(entity.getStarcount());
        userInfoGdBean.setId(entity.getId());
        userInfoGdBean.setUserphone(entity.getUserphone());
        mDao.update(userInfoGdBean);
    }

    public void updateUserLevelInfo(String level){
        UserInfoGdBean userInfoGdBean = new UserInfoGdBean();
        userInfoGdBean.setLevel(level);
        mDao.insertOrReplace(userInfoGdBean);
    }

    public List<UserInfoGdBean> getUserInfo(){  //page 分页0开始每页15条
        List<UserInfoGdBean> mlist = mDao.queryBuilder().list();
        return mlist;
    }

    /*public List<UserInfoGdBean> getOperatorInfoUser(int page){  //page 分页0开始每页15条
        List<UserInfoGdBean> mlist = mDao.queryBuilder().where(OperatorInfoBeanDao.Properties.Type.eq(0))
                .orderDesc(OperatorInfoBeanDao.Properties.CreateDate)
                .offset(15*page)
                .limit(20)
                .list();
        return mlist;
    }*/



    public List<UserInfoGdBean> getInfoUsername(String  username){  //page 分页0开始每页15条
        List<UserInfoGdBean> mlist = mDao.queryBuilder().where(UserInfoGdBeanDao.Properties.Userphone.eq(username)).list();
        return mlist;
    }

    public List<UserInfoGdBean> getInfoUserID(String  username){  //page 分页0开始每页15条
        List<UserInfoGdBean> mlist = mDao.queryBuilder().where(UserInfoGdBeanDao.Properties.Userphone.eq(username)).list();
        return mlist;
    }

    public List<UserInfoGdBean> getInfoUserLevel(){  //page 分页0开始每页15条
        List<UserInfoGdBean> mlist = mDao.queryBuilder().list();
        return mlist;
    }

    public List<UserInfoGdBean> getInfoNoPassLevel(){  //page 分页0开始每页15条
        List<UserInfoGdBean> mlist = mDao.queryBuilder().list();
        return mlist;
    }

   /* public List<UserInfoGdBean> getInfoUserProp(String  propName){  //page 分页0开始每页15条
        List<UserInfoGdBean> mlist = mDao.queryBuilder().where(UserInfoGdBeanDao.Properties.Propname.eq(propName)).list();
        return mlist;
    }*/

   /* public int getUserInfoCount(){  //page 分页0开始每页10条
        List<UserInfoGdBean> mlist = mDao.queryBuilder().list();
        int count = (mlist.size() - 1) / 20 + 1;
        return count;
    }*/

    public int getUserInfoCount(){  //page 分页0开始每页10条
        List<UserInfoGdBean> mlist = mDao.queryBuilder().list();
        return mlist.size();
    }




    /*public List<GuestRegistrationBean> getLobbyCompany(String name,String sex){  //page 分页0开始每页15条
        List<GuestRegistrationBean> mlist = mDao.queryBuilder()
                .where(GuestRegistrationBeanDao.Properties.Username.eq(name),
                        GuestRegistrationBeanDao.Properties.Gender.eq(sex))
                .orderDesc(GuestRegistrationBeanDao.Properties.CreateDate).list(); //.orderDesc(VisitorMsgEntityDao.Properties.Start_time).list();
        List<GuestRegistrationBean> mData = new ArrayList<>();
        if(mlist != null && mlist.size() > 0) {
            for (GuestRegistrationBean visit:mlist) {
                String createAt = visit.getCreateDate();
                Date date1 = DateUtil.stringToDate(createAt, "yyyy-MM-dd");
                //long aLong = Long.parseLong(createAt);
                long timeMillis = System.currentTimeMillis();
                Date date = DateUtil.longToDate(timeMillis, "yyyy-MM-dd");
                int i = date1.compareTo(date);
                if(i <= 0){
                    mData.add(visit);
                }
            }
        }
        return mData;
    }*/


}
